package git.jasonch.isp.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import git.jasonch.isp.entity.Isp;
import git.jasonch.isp.mapper.IspMapper;
import git.jasonch.isp.service.IspService;
import git.jasonch.isp.utils.UUIDUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * projectName : isp
 * className: IspServiceImpl
 * description: TODO 类描述
 *
 * @author : git.jas0nch
 * date: 2022-02-07
 */

@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class IspServiceImpl implements IspService {

    private final IspMapper ispMapper;

    @Override
    public Integer addIsp(Isp isp) {

        isp.setId(UUIDUtils.Get_uuid());
        isp.setDate(new Date());
        return ispMapper.insert(isp);
    }

    @Override
    public Integer deleteIsp(String id) {

        // or the wrapper

        return ispMapper.deleteById(id);
    }

    @Override
    public Integer updateIsp(Isp isp) {
        return ispMapper.updateById(isp);
    }

    @Override
    public Isp queryOne(String id) {
        return ispMapper.selectById(id);
    }

    @Override
    public List<Isp> queryIspAll() {

        LambdaQueryWrapper<Isp> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(Isp::getDate);
        return ispMapper.selectList(wrapper);
    }
}
